<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="https://cdn.bootcss.com/layer/3.0.1/skin/default/layer.min.css">
<link rel="stylesheet" href="../../../layui/css/layui.css">
<link rel="stylesheet" href="../../../css/byking.css">
</head>
<body id="modifymenu">
	<div class="byking-form">
		<form class="layui-form" action="">
		
			<div class="layui-form-item">
				<label class="layui-form-label">菜单名称</label>
				<div class="layui-input-block">
					<input type="text" id="menu_name" name="menu_name" required lay-verify="required"
						placeholder="请输入菜单名称" autocomplete="off" class="layui-input" value="{{menu.menu_name}}">
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label">菜单描述</label>
				<div class="layui-input-block">
					<input type="text" id="description" name="description" required lay-verify="required"
						placeholder="请输入菜单描述" autocomplete="off" class="layui-input" value="{{menu.description}}">
				</div>
			</div>
			
			<div class="layui-form-item">
				<label class="layui-form-label">链接</label>
				<div class="layui-input-block">
					<input type="text" name="menu_url" id="menu_url"  value="{{menu.menu_url}}" 
						placeholder="请输入链接" autocomplete="off" class="layui-input">
				</div>
			</div>
			
			<div class="layui-form-item">
				<label class="layui-form-label">菜单图标</label>
				<div class="layui-input-block">
					<input type="text" name="image" id="image" required lay-verify="required"
						placeholder="请输入部门图标" autocomplete="off" class="layui-input"  value="{{menu.image}}">
				</div>
			</div>
			
			<div class="layui-form-item">
				<label class="layui-form-label">排序</label>
				<div class="layui-input-block">
					<input type="text" name="sorting" id="sorting" required lay-verify="number"
						autocomplete="off" class="layui-input"  value="{{menu.sorting}}">
				</div>
			</div>

			<div class="layui-form-item">
				<div class="layui-input-block">
					<button class="layui-btn " lay-submit lay-filter="formDemo">立即提交</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				</div>
			</div>
		</form>
	</div>

	<!-- jQuery -->
	<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
	<!-- jquery.cookie -->
	<script src="https://cdn.bootcss.com/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
	<!-- layer -->
	<script src="https://cdn.bootcss.com/layer/3.0.1/layer.min.js"></script>
	<!-- vue -->
	<script src="http://cdn.jsdelivr.net/vue/1.0.7/vue.min.js"></script>
	<script src="../../../layui/layui.js"></script>
	<script src="../../../js/byking.js"></script>
	<script src="../../../js/hostconfig.js"></script>
	<script>
	var guid = $byking.getUrlParam("guid");

	var modifymenu = new Vue({
        el: "#modifymenu",
        data: {
        	menu: null
        },
        methods: {
        	getMenuInfo: function() {
        		
        		var url = $hostconfig.sysAuthHost+"/menu/info?guid="+guid;
    			$byking.getJSONWithToken(url,function(data){
    				modifymenu.menu = data.data;
    			});
        	}
        }
    });
	
	modifymenu.getMenuInfo();
		
	var submitflag = true;
	layui.use('form', function() {
		var form = layui.form();
		//监听提交
		form.on('submit(formDemo)', function(data) {
			$(".layui-btn").addClass("layui-btn-disabled");
			var data = data.field;
			if(!submitflag){
				return false;
			}
			submitflag = false;
			data.guid = guid;
			data.update_by = $byking.getCookieValue("user_guid");
			data.user_guid = $byking.getCookieValue("user_guid");
			var url = $hostconfig.sysAuthHost+"/menu/add";
			$byking.postJSONWithToken(url,data,function(data){
				layer.msg("修改成功");
				var index = parent.layer.getFrameIndex(window.name);  
				parent.setData();
				parent.layer.close(index); 
			},function(data){
				layer.msg(data.responseJSON.message);
			});
			return false;
		});
	});
	</script>
</body>
</html>